package com.tianlang.domain.pojo;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;

/**
 * 
 * @author mcp
 *
 */
@Entity
@Table(name = "account")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@GenericGenerator(name = "uuid", strategy = "uuid")
public class Account {

	@Id
	@GeneratedValue(generator = "uuid")
	private String id;
	@Column
	private String userName;
	@Column
	private String password;
	@Column
	@Temporal(TemporalType.TIMESTAMP)
	@CreationTimestamp
	private Date created;
	/**
	 * @ManyToMany 指定多对多关系
	 * @Cascade 设置级联关系
	 * @JoinTable 指定第三张表
	 * joinColumns 本表与中间表的外键对应
	 */
	@ManyToMany
	@Cascade(value = { CascadeType.SAVE_UPDATE })
	@JoinTable(name = "account_role", joinColumns = { @JoinColumn(name = "accountId") }, inverseJoinColumns = {
			@JoinColumn(name = "roleId") })
	private List<Role> roles;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

}
